package org.cfg;

import org.apache.commons.collections4.MapUtils;
import com.sojoys.artifact.build.data.base.BaseCfg;
import java.util.List;
import org.utils.timeframe.TimeFrame;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.ToolCopy;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
/**
 * 副本关卡组
 */
public class DungeonLevelGroupCfg extends BaseCfg<DungeonLevelGroupCfg> implements org.utils.timeframe.TimeFrame{

	/**
	 * 数据库表名称
	 */
	public static final String TABLE_NAME = "dungeon_level_group";
	/**
	 * 完整类名称
	 */
	public static final String CLASS_NAME = "org.cfg.DungeonLevelGroupCfg"; 
	/**
	 * 字段个数
	 */
	public static final int COLUMN_COUNT= 11;
	/**
	 * 数据库源字段注释
	 */
	public static final String[] SOURCE_COLUMN_REMARKS = new String[]{"","副本类型","限制次数","开启时间类型","时间段","周期类型","周期参数","购买次数类型","最大购买次数","价格","奖励",};
	/**
	 * 数据库源字段名字
	 */
	public static final String[] SOURCE_COLUMN_NAMES = new String[]{"id","dungeonType","countLimit","openTimeType","timeFrame","cycleType","cycleParam","buyCountType","buyCountLimit","price","reward",};
	/**
	 * 拼音字段名字
	 */
	public static final String[] PINGYING_COLUMN_NAMES = new String[]{"id","dungeonType","countLimit","openTimeType","timeFrame","cycleType","cycleParam","buyCountType","buyCountLimit","price","reward",};
	/**
	 * HashCode字段名字
	 */
	public static final Integer[] HASHCODE_COLUMN_NAMES = new Integer[]{3355,-228806380,-1053008916,410961937,13508256,-1561282240,-1159516345,1027722499,1786758930,106934601,-934326481,};
	/**
	 * 字段基本类型
	 */
	public static final String[] COLUMN_BASICTYPES = new String[]{"int","int","int","int","List","int","int","int","int","Map","Map",};
	/**
	 * 字段引用类型
	 */
	public static final Class[] COLUMN_CLASSTYPES = new Class[]{Integer.class,Integer.class,Integer.class,Integer.class,List.class,Integer.class,Integer.class,Integer.class,Integer.class,Map.class,Map.class,};
	
	/**
	 * id
	 */
	private int id;
	
	/**
	 * 副本类型
	 */
	private int dungeonType;
	
	/**
	 * 限制次数
	 */
	private int countLimit;
	
	/**
	 * 开启时间类型
	 */
	private int openTimeType;
	
	/**
	 * 时间段
	 */
	private List timeFrame;
	
	/**
	 * 周期类型
	 */
	private int cycleType;
	
	/**
	 * 周期参数
	 */
	private int cycleParam;
	
	/**
	 * 购买次数类型
	 */
	private int buyCountType;
	
	/**
	 * 最大购买次数
	 */
	private int buyCountLimit;
	
	/**
	 * 价格
	 */
	private Map price;
	
	/**
	 * 奖励
	 */
	private Map reward;
	
	
	
	public static DungeonLevelGroupCfg builder() {
		DungeonLevelGroupCfg dungeonLevelGroupCfg = new DungeonLevelGroupCfg();
		return dungeonLevelGroupCfg;
	}
	
	/**
	 * id
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * 副本类型
	 */
	public int getDungeonType() {
		return dungeonType;
	}
	
	/**
	 * 限制次数
	 */
	public int getCountLimit() {
		return countLimit;
	}
	
	/**
	 * 开启时间类型
	 */
	public int getOpenTimeType() {
		return openTimeType;
	}
	
	/**
	 * 时间段
	 */
	public List getTimeFrame() {
		return timeFrame;
	}
	
	/**
	 * 周期类型
	 */
	public int getCycleType() {
		return cycleType;
	}
	
	/**
	 * 周期参数
	 */
	public int getCycleParam() {
		return cycleParam;
	}
	
	/**
	 * 购买次数类型
	 */
	public int getBuyCountType() {
		return buyCountType;
	}
	
	/**
	 * 最大购买次数
	 */
	public int getBuyCountLimit() {
		return buyCountLimit;
	}
	
	/**
	 * 价格
	 */
	public Map getPrice() {
		return price;
	}
	
	/**
	 * 奖励
	 */
	public Map getReward() {
		return reward;
	}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.dungeonType;
        values[2] = this.countLimit;
        values[3] = this.openTimeType;
        values[4] = this.timeFrame;
        values[5] = this.cycleType;
        values[6] = this.cycleParam;
        values[7] = this.buyCountType;
        values[8] = this.buyCountLimit;
        values[9] = this.price;
        values[10] = this.reward;
        return values;
	}
	
	protected DungeonLevelGroupCfg createColumeValues(Object[] vals) {
		this.id = (int)vals[0];
		this.dungeonType = (int)vals[1];
		this.countLimit = (int)vals[2];
		this.openTimeType = (int)vals[3];
		this.timeFrame = (List)vals[4];
		this.cycleType = (int)vals[5];
		this.cycleParam = (int)vals[6];
		this.buyCountType = (int)vals[7];
		this.buyCountLimit = (int)vals[8];
		this.price = (Map)vals[9];
		this.reward = (Map)vals[10];
		return this;
	}
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.dungeonType);
        map.put(keys[2], this.countLimit);
        map.put(keys[3], this.openTimeType);
        map.put(keys[4], this.timeFrame);
        map.put(keys[5], this.cycleType);
        map.put(keys[6], this.cycleParam);
        map.put(keys[7], this.buyCountType);
        map.put(keys[8], this.buyCountLimit);
        map.put(keys[9], this.price);
        map.put(keys[10], this.reward);
        return map;
    }
    
    protected DungeonLevelGroupCfg createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.dungeonType = (int)map.get(keys[1]);
   		this.countLimit = (int)map.get(keys[2]);
   		this.openTimeType = (int)map.get(keys[3]);
   		this.timeFrame = (List)map.get(keys[4]);
   		this.cycleType = (int)map.get(keys[5]);
   		this.cycleParam = (int)map.get(keys[6]);
   		this.buyCountType = (int)map.get(keys[7]);
   		this.buyCountLimit = (int)map.get(keys[8]);
   		this.price = (Map)map.get(keys[9]);
   		this.reward = (Map)map.get(keys[10]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.dungeonType);
        obj.put(keys[2], this.countLimit);
        obj.put(keys[3], this.openTimeType);
        obj.put(keys[4], this.timeFrame);
        obj.put(keys[5], this.cycleType);
        obj.put(keys[6], this.cycleParam);
        obj.put(keys[7], this.buyCountType);
        obj.put(keys[8], this.buyCountLimit);
        obj.put(keys[9], this.price);
        obj.put(keys[10], this.reward);
        return obj;
    }
    
    protected DungeonLevelGroupCfg createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.dungeonType = obj.getIntValue(keys[1]);
	    this.countLimit = obj.getIntValue(keys[2]);
	    this.openTimeType = obj.getIntValue(keys[3]);
		this.timeFrame = obj.getObject(keys[4],List.class);
	    this.cycleType = obj.getIntValue(keys[5]);
	    this.cycleParam = obj.getIntValue(keys[6]);
	    this.buyCountType = obj.getIntValue(keys[7]);
	    this.buyCountLimit = obj.getIntValue(keys[8]);
		this.price = obj.getObject(keys[9],Map.class);
		this.reward = obj.getObject(keys[10],Map.class);
        return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeInt(this.dungeonType);
	    byteBuf.writeInt(this.countLimit);
	    byteBuf.writeInt(this.openTimeType);
	    byteBuf.writeObject(this.timeFrame);
	    byteBuf.writeInt(this.cycleType);
	    byteBuf.writeInt(this.cycleParam);
	    byteBuf.writeInt(this.buyCountType);
	    byteBuf.writeInt(this.buyCountLimit);
	    byteBuf.writeObject(this.price);
	    byteBuf.writeObject(this.reward);
    }
	
	protected DungeonLevelGroupCfg readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.dungeonType = byteBuf.readInt(null);
	    this.countLimit = byteBuf.readInt(null);
	    this.openTimeType = byteBuf.readInt(null);
	    this.timeFrame = (List)byteBuf.readObject();
	    this.cycleType = byteBuf.readInt(null);
	    this.cycleParam = byteBuf.readInt(null);
	    this.buyCountType = byteBuf.readInt(null);
	    this.buyCountLimit = byteBuf.readInt(null);
	    this.price = (Map)byteBuf.readObject();
	    this.reward = (Map)byteBuf.readObject();
	    return this;
	}
	
	public DungeonLevelGroupCfg deepCopy(){
		DungeonLevelGroupCfg dungeonLevelGroupCfg = null;
		try {
			dungeonLevelGroupCfg = (DungeonLevelGroupCfg) super.clone();
		    dungeonLevelGroupCfg.timeFrame = ToolCopy.copyObject(this.timeFrame);
		    dungeonLevelGroupCfg.price = ToolCopy.copyObject(this.price);
		    dungeonLevelGroupCfg.reward = ToolCopy.copyObject(this.reward);
			return dungeonLevelGroupCfg;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return dungeonLevelGroupCfg;
	}
//自定义内容起始位置

	/**
	 * 获取奖励
	 */
	public Map<Integer,Integer> getRewardByDifficultyAndStar(int difficulty,int star){
		Map map = (Map) reward.get(difficulty);
		if (map != null){
			return (Map<Integer, Integer>) map.get(star);
		}
		return null;
	}

//自定义内容结束位置
}
